home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / dhtmlunl / dhtml.exe / CD Content / Chap15 / dun15_5.txt < prev    next >
Encoding:
Text File  |  1997-12-18  |  1.8 KB  |  55 lines

  1. <IMG NAME=arrow SRC="arrow.gif" ALIGN=left>
  2.  
  3. <DIV ID=banner STYLE="position: absolute; left: 72; top: 15;">
  4.   <FONT FACE="Arial, Helvetica" SIZE=+2>
  5.       Exposing Page Elements Cross-Browser
  6.   </FONT>
  7. </DIV>
  8.  
  9.  
  10. <SCRIPT>
  11.   // Detect if browser is IE4 and if so, assign objectRoot to contain
  12.   // 'document.all' instead of 'document'
  13.   //
  14.   objectRoot = "document";
  15.   if (navigator.appName.indexOf("Internet Explorer") != -1 &&
  16.       navigator.appVersion.charAt(0) == '4')
  17.         objectRoot = "document.all";
  18. </SCRIPT>
  19.  
  20.  
  21. <BR><BR>
  22. <P>The <TT>DIV</TT> element is normally reflected as
  23. <TT>document.banner</TT> in Communicator 4.0 and
  24. <TT>document.all.banner</TT> in IE4.  By assigning
  25. <TT>objectRoot</TT> to contain the differences in the object hierarchy,
  26. the <TT>eval()</TT> function can be used to dynamically access the
  27. <TT>DIV</TT> element using the correct notation for each browser.</P>
  28.  
  29. <P>The attributes of the <TT>DIV</TT> element that are reflected in both
  30. browsers include:</P>
  31.  
  32. <BLOCKQUOTE>
  33. <SCRIPT>
  34.   document.writeln("<B>id:</B> " + eval(objectRoot + ".banner.id"));
  35.   document.writeln("<BR>");
  36. </SCRIPT>
  37. </BLOCKQUOTE>
  38.  
  39. <P>The <TT>IMG</TT> element is dynamically accessed as
  40. <TT>document.arrow</TT> in Communicator 4.0 and
  41. <TT>document.all.arrow</TT> in IE4 using the <TT>objectRoot</TT>
  42. variable and the <TT>eval()</TT> function.  </P>
  43.  
  44. <P>The attributes of the <TT>IMG</TT> element that are reflected in both
  45. browsers include:</P>
  46.  
  47. <BLOCKQUOTE>
  48. <SCRIPT>
  49.    document.writeln("<B>name:</B> " + eval(objectRoot + ".arrow.name"));
  50.    document.writeln("<BR>");
  51.    document.writeln("<B>src:</B> " + eval(objectRoot + ".arrow.src"));
  52.    document.writeln("<BR>");
  53. </SCRIPT>
  54. </BLOCKQUOTE>
  55.